#ifndef _Weapons_H
#define _Weapons_H

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

#include <vector>

#include "objects.h"
#include "particle_factory.h"

#include "particle_factory.h"
#include "ammo.h"


//state of weapon
enum Weapon_State
{
	WS_NONE,
	WS_READY,
	WS_FIRING,
	WS_RELOADING,
	WS_DELAY
};








/* Main Weapons handler */
class Weapons : public Objects
{

	public:
		Weapons();


	//Load the whole kitten kabootal!
		static bool Load(std::string cfg_location);

		//Draw Weapon
		//void Draw( sf::RenderWindow& App );

	
	//Get/Set if we can shoot
		bool Get_isReady();
		void Set_isReady(bool wpnReady);

	//Get/Set for Bullet Name
		std::string Get_BulletName() { return bullet_name; }
		void Set_BulletName(std::string new_bName) { bullet_name = new_bName; }

		//Get/Set Spread Angle
		int Get_SpreadAngle() { return spread_angle; }
		void Set_SpreadAngle(int new_spreadAngle) { spread_angle = new_spreadAngle; }

		//Get ammo per shot
		int Get_AmmoPerShot() { return ammo_per_shot; }
	

		//Get cursor sprite
		sf::Sprite Get_CursorSprite() { return cursor; }

	//Get Weapon specs from its folder
		bool Get_Config(std::string folder_name);

		void Animation_Update();
		void Mechanics_Update();

		//Spawn Bullets
		void Spawn_Bullet(Particles &ammo_type);


		//Loo


	//Weel important stuff here
		void Set_PivitPoint(sf::Vector2f pp);
		sf::Vector2f Get_PivitPoint() { return pivit_point; }

		void Set_EndPoint(sf::Vector2f ep);
		sf::Vector2f Get_EndPoint() { return current_ep; }


		//Calculate real end point
		sf::Vector2f Weapons::Get_MuzzlePoint(sf::Vector2f temp_direction);
	

		//Get the Max weapons used 
		static int Get_MaxWeapons() { return max_weapons-1; }


//THE LIST!
		static std::vector< std::string > List;
		


		//Sounds
		sf::Sound s_fire;
		sf::Sprite cursor, muzzle_flash;

		//Animation info
		Animation_Frames shootFrame;



	protected:

		static sf::Image Load_Cursor(std::string cursorLocation);
		sf::Vector2f Get_VelocityDirection();
	

		sf::Image cursor_img, *muzzleFlash_img;
	

		
		//Ammo related vars
		std::string bullet_name;

		int current_ammo;
		int ammo_per_shot;
		int max_ammo;
		
		int spread_angle;


		//Max weapons loaded into game
		static int max_weapons;


		//Weapon reference number
	//Slight delay before shooting again
		float fire_delay;

	
		bool use_custom_cursor;

		bool isReady;

		//important vars:
		//Pivit point for the gun
		//End point, to shoot from
		//cursor position
		sf::Vector2f pivit_point, cursor_pos;
		//muzzle point for gun
		sf::Vector2f muzzle_point, inverse_mp;

//End Point handler's
		sf::Vector2f end_point, current_ep, inverse_ep;
	
		
//Amunition related things
		
		

		
	
		//Sounds used by weapons
		sf::SoundBuffer SND_fire;
		
		
		bool Load_Sounds(sf::Sound& s, sf::SoundBuffer& b, std::string snd_location);



		//All Powerfull Weapon List
		
		static bool Get_WeaponList();

};

extern std::vector< Weapons > guns;

#endif